/**
 * @description 路由
 * @author Xiaohui Zeng
 * @version 2021/2/26
 * @Email: 1257538859@qq.com
 * @WeChat: badiweier
 */
import layout from '@/layouts/base-layout/index.vue'

import dashboard from './modules/dashboard'
import form from './modules/form'
import list from './modules/list'
/**
 * 配置说明
 * 主框架内的路由才会在菜单显示
 * @meta: {
   name: String 菜单名称 (必填 必须和组件name保持一致),
   icon: String 饿了么UI的图标 (非必填) https://element-plus.gitee.io/zh-CN/component/icon.html 注意：icon iconSvg二选一即可 二者可并存 但iconSvg优先级更高
   iconSvg: String svg图标 (非必填) 加载的是 src/icons 目录下的svg图标名称(不包含.svg后缀) svg图标如何使用 请参考src/components/SvgIcon/index.vue
   hidden: Boolean 菜单是否显示 (非必填) 默认true
   showTab: Boolean 菜单是否显示在多页签中 (非必填) 默认true
   cache Boolean 页面是否缓存 (非必填) 默认false
   affix Boolean 标签是否始终粘贴在多页签中 (非必填) 默认false
   singlePage Boolean 是否是单页面 如果只有一个子路由默认会渲染嵌套菜单，设置此属性可只渲染子菜单 (非必填) 默认false
 }
 eg: meta: { name: '主页2', icon: 'el-icon-help', iconSvg: 'home', hidden: true, showTab: false }
 * @component (多级菜单必填) eg: component: layoutChild 多级菜单记得加子路由模板 否则页面渲染不出来
 */

/**
 * 主框架内 不需要鉴权的路由
 */
export const layoutNoPermission = [
  {
    path: '/',
    redirect: {
      name: 'dashboard-home'
    },
    meta: { hidden: true }
  },
  dashboard,
  form,
  list
]
/**
 * 错误提示页面 必须放在异步路由最后 否则刷新后页面直接404
 */
export const errorPage = [
  {
    path: '/errorPage',
    name: 'errorPage',
    component: layout,
    meta: { name: '异常页面', iconSvg: 'menu-error' },
    children: [
      {
        path: '403',
        name: '403',
        meta: {
          name: '403'
        },
        component: () => import('@/views/error-page/403.vue')
      },
      {
        path: '404',
        name: '404',
        meta: { name: '404' },
        component: () => import('@/views/error-page/404.vue')
      },
      {
        path: '500',
        name: '500',
        meta: { name: '500' },
        component: () => import('@/views/error-page/500.vue')
      }
    ]
  },
  {
    path: '/:path404(.*)*', // 404必须放在异步路由最后
    redirect: '/errorPage/404',
    meta: { hidden: true }
  }
]
/**
 * 主框架内 需要鉴权的路由 错误提示页面 必须放在异步路由最后
 */
export const layoutPermission = [
  {
    path: '/example',
    name: 'example',
    component: layout,
    meta: { name: 'Example', iconSvg: 'home', ruleId: 1 },
    children: [
      {
        path: 'list',
        name: 'example-list',
        meta: { name: 'list', ruleId: 2 },
        component: () => import('@/views/example/list.vue')
      },
      {
        path: 'tables',
        name: 'example-tables',
        meta: { name: 'tables', ruleId: 3 },
        component: () => import('@/views/example/tables.vue')
      }
    ]
  },
  ...errorPage
]

/**
 * 主框架外 免登录
 */
export const layoutOut = [
  {
    path: '/login',
    name: 'login',
    meta: {
      name: '登录'
    },
    component: () => import('@/views/login/login.vue')
  },
  {
    path: '/register',
    name: 'register',
    meta: {
      name: '注册'
    },
    component: () => import('@/views/login/register.vue')
  }
]

export const routes = [
  ...layoutNoPermission,
  ...layoutOut
]
